package com.mflex.flexwi.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mflex.flexwi.R;
import com.mflex.flexwi.bean.SignItem;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class SignAdapter extends BaseAdapter {
    List<SignItem> items;
    Activity context;

    public SignAdapter(Activity context, List<SignItem> items) {
        this.items = items;
        this.context = context;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SignItem item = items.get(position);
        View view = convertView;
        view = context.getLayoutInflater().inflate(R.layout.sign_list,null);
        ((TextView) view.findViewById(R.id.txtlDocNumber)).setText(StringUtils.equals(item.getDocumentnumber(), "anyType{}") ? StringUtils.EMPTY : item.getDocumentnumber());
        ((TextView) view.findViewById(R.id.txtlDocName)).setText(StringUtils.equals(item.getDocumentname(), "anyType{}") ? StringUtils.EMPTY : item.getDocumentname());
        ((TextView) view.findViewById(R.id.txtlEmployeeId)).setText(StringUtils.equals(item.getEmployeeid(), "anyType{}") ? StringUtils.EMPTY : item.getEmployeeid());
        ((TextView) view.findViewById(R.id.txtlLeaderNo)).setText(StringUtils.equals(item.getLeaderid(), "anyType{}") ? StringUtils.EMPTY : item.getLeaderid());
        ((TextView) view.findViewById(R.id.txtlSignTime)).setText(StringUtils.equals(item.getSigntime(), "anyType{}") ? StringUtils.EMPTY : item.getSigntime());
        if(position %2==0){
            ((LinearLayout) view.findViewById(R.id.txtSignList)).setBackgroundColor(Color.rgb(221,221,221));
        }
        return view;
    }
}
